<#assign module="zhuanxian"/>

<@override name="header">
    <link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
<#--<link rel="stylesheet" href="${ctx}/assets/css/bootstrap-select.min.css">-->
    <link rel="stylesheet" href="${ctx}/assets/css/bootstrap-multiselect.css">
    <!-- import stylesheet -->
    <link rel="stylesheet" href="//unpkg.com/iview/dist/styles/iview.css">
    <style>
        /* autocomplete */
        div.ac {
            border: 1px solid #ccc;
            position: absolute;
            display: none;
            overflow: auto;
            background-color: #ffffff;
            z-index: 3000;
        }

        div.ac > ul {
            margin-top: 10px;
            padding: 0;
        }

        div.ac > ul > li {
            height: 33px;
            line-height: 33px;
            cursor: pointer;
        }

        div.ac > ul > li:hover {
            background: #eee;
        }

        div.ac > ul > li > div span {
            padding-left: 15px;
        }

        div.ac > ul > li > div span em {
            color: red;
            font-style: normal;
        }
    </style>
</@override>
<@override name="body">
    <div class="tabbable tabs-left">
        <div class="row">
            <div class="col-xs-12">
                <div class="orders-navt">
                    <ul class="orders-nav">
                        <@shiro.hasPermission name='zhuanxianCar'>
                            <li class="orders-click"><a data-toggle="tab" href="${ctx}/zhuanxian/cars"
                                                        class="orders-click-a">车辆</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='zhuanxianLine'>
                            <li><a href="${ctx}/zhuanxian/lines">线路</a></li>
                        </@shiro.hasPermission>
                    </ul>
                </div>
                <@shiro.hasPermission name='addZXVehicle'>
                    <div class="orders-navh">
                        <#--id="addOrder" class="add"-->
                        <button class="pull-right btn btn-primary addCar"><i class="icon-plus"></i>&nbsp;添加车辆</button>
                    </div>
                </@shiro.hasPermission>

            </div>
        </div>
    </div>

    <div class="tab-content">
        <div class="container-fluid ">
            <div class="row query-pad">
                <div class="col-xs-11" style="padding: 0px;">
                    <@shiro.isMainCompany>
                        <div class="col-xs-4 input-query">
                            <span>所属公司:</span>
                            <input type="text" class="form-control form-contb" id="companyName1" name="companyName1"
                                   placeholder="请输入公司名字"/>
                        </div>
                    </@shiro.isMainCompany>
                    <div class="col-xs-4 input-query">
                        <span>线路:</span>
                        <input type="text" class="form-control form-contb" id="line1" name="line1"
                               placeholder="请输入汽车线路"/>
                    </div>
                    <div class="col-xs-4 input-query">
                        <span>服务人员信息:</span>
                        <input type="text" class="form-control form-contb" id="employName1" name="employName1"
                               placeholder="请输入员工名字、电话"/>
                    </div>
                </div>
                <div class="col-xs-1" style="padding: 0px;">
                    <div class="input-query-bttom">
                        <button id="searchButton" type="button">查询</button>
                    </div>
                </div>
            </div>
            <div class="row query-pad choose" style="display: none;">
                <div class="col-xs-12" style="padding:0px; line-height:3;">
                    <div class="col-xs-4">
                        <div class="input-query " style="padding:0px; line-height:3;">
                            <span>车牌号:</span>
                            <input type="text" class="form-control form-contb" id="carNumber1" name="carNumber1"
                                   placeholder="请输入车牌号"/>
                        </div>
                    </div>
                    <div class="media-wit melect col-xs-4" style="padding:15px; line-height:3;">
                        <span>车辆状态:</span>
                        <input type="checkbox" name="status" value="1">
                        <span class="checkbox-margin">空闲</span>
                        <input type="checkbox" name="status" value="2">
                        <span class="checkbox-margin">忙碌</span>
                    </div>

                </div>
            </div>
            <div class="query-jiant">
                <a href="#"><img id="jiant" src="${ctx}/assets/img/jiant2.png"/></a>
            </div>
        </div>
    </div>

    <!--列表-->
    <div class="tabta-content">
        <table class="table table-condensed table-striped">
            <tbody id="car_tbody">
            <tr>
            <tr>
                <th>状态</th>
                <th>车牌号</th>
                <th>车辆名称</th>
                <@shiro.isMainCompany>
                    <th>所属公司</th>
                </@shiro.isMainCompany>
                <th>所属线路</th>
                <th>驾驶员工</th>
                <th>乘坐人数</th>
                <th>操作</th>
            </tr>
            </tr>
            </tbody>
        </table>

        <ul class="pagination pull-left pagination-sm pageshow" style="display:none;">
            <li><a></a></li>
        </ul>
        <ul class="pagination pull-left pagination-sm pagedata" style="display:none;">
        </ul>
    </div>



    <!--添加车辆-->
    <div class="form-horizontal">
        <div class="modal fade" id="dialog_car" data-backdrop="static">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="false">&times;</button>
                        <h4 class="modal-title">添加车辆</h4>
                    </div>
                    <div class="modal-body">
                        <form action="" method="post">
                            <input type="hidden" id="employId" name="employId">
                            <@shiro.isMainCompany>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">所属公司:</label>
                                    <div class="col-sm-9">
                                        <select class="form-control" id="companyId">
                                            <#if companys??>
                                                <#list companys as company>
                                                    <option value="${company.id}"
                                                            <#if companyId?? && companyId==company.id>selected="selected"</#if>>${company.abbreviation?if_exists}</option>
                                                </#list>
                                            </#if>
                                        </select>
                                    </div>
                                </div>
                            </@shiro.isMainCompany>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">车辆名称:</label>
                                <div class="col-sm-9">
                                    <input id="carName" class="form-control"></input>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">车牌号:</label>
                                <div class="col-sm-9">
                                    <input id="carNumber" class="form-control" placeholder="如:京A12345"></input>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">可乘坐人数:</label>
                                <div class="col-sm-9">
                                    <input id="ridepeopleNumber" class="form-control" type="number" min="1"></input>
                                </div>
                            </div>
                            <label style="margin-left:150px;color:red">温馨提示：乘坐人数是除去司机的可乘坐人数</label><br>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">线路:</label>
                                <div class="col-sm-9">
                                    <select class="form-control" multiple="multiple" multiple id="lineId">
<#--                                        <#if (lines??&&lines?size>0)>-->
<#--                                            <#list lines as line>-->
<#--                                                <option value="${line.id}">-->
<#--                                                    ${line.name?if_exists}<@shiro.isMainCompany>&emsp;&emsp;&emsp;${line.companyName?if_exists}</@shiro.isMainCompany></option>-->
<#--                                            </#list>-->
<#--                                        <#else>-->
<#--                                            <option value="">暂无线路</option>-->
<#--                                        </#if>-->
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">指派服务人员:</label>
                                <div id="text_div" class="col-sm-9">
                                    <input class="form-control" id="employName" name="employName"
                                           placeholder="输入:工号、电话、姓名" type="text"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-5">
                                </div>
                                <div class="col-sm-3">
                                    <input type="button" class="btn btn-primary" id="save" value="确定">
                                    <button type="button" class="btn btn-default" id="close_modal">关闭</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--修改车辆信息-->
    <div class="form-horizontal">
        <div class="modal fade" id="dialog_car_update" data-backdrop="static">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="false">&times;</button>
                        <h4 class="modal-title">修改车辆信息</h4>
                    </div>
                    <div class="modal-body">
                        <form action="" method="post">
                            <input type="hidden" id="carId">
                            <input type="hidden" id="employId2">
                            <@shiro.isMainCompany>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">所属公司:</label>
                                    <div class="col-sm-9">
                                        <select class="form-control" id="companyId2">
                                            <#if companys??>
                                                <#list companys as company>
                                                    <option value="${company.id}"
                                                            <#if companyId?? && companyId==company.id>selected="selected"</#if>>${company.abbreviation?if_exists}</option>
                                                </#list>
                                            </#if>
                                        </select>
                                    </div>
                                </div>
                            </@shiro.isMainCompany>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">车辆名称:</label>
                                <div class="col-sm-9">
                                    <input id="carName2" class="form-control"></input>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">车牌号:</label>
                                <div class="col-sm-9">
                                    <input id="carNumber2" class="form-control" placeholder="如:京A12345"></input>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">可乘坐人数:</label>
                                <div class="col-sm-9">
                                    <input id="ridepeopleNumber2" class="form-control" type="number" min="1"></input>
                                </div>
                            </div>
                            <label style="margin-left:150px;color:red">温馨提示：乘坐人数是除去司机的可乘坐人数</label><br>
                            <div class="form-group" id="app">
                                <label class="col-sm-3 control-label">线路:</label>
                                <div class="col-sm-9">
                                    <select class="form-control" multiple="multiple" multiple id="lineId2">
                                        <#if (lines??&&lines?size>0)>
                                            <#list lines as line>
                                                <option value="${line.id}">
                                                    ${line.name?if_exists}<@shiro.isMainCompany>&emsp;&emsp;&emsp;${line.companyName?if_exists}</@shiro.isMainCompany></option>
                                            </#list>
                                        <#else>
                                            <option value="">暂无线路</option>
                                        </#if>
                                    </select>
<#--                                    <i-select v-model="model10" multiple style="width:260px">-->
<#--                                        <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>-->
<#--                                    </i-select>-->
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">状态:</label>
                                <div class="col-sm-9">
                                    <select class="form-control" id="status2">
                                        <option value="1">空闲</option>
                                        <option value="2">忙碌</option>
                                        <option value="3">离线</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">指派服务人员:</label>
                                <div id="text_div" class="col-sm-9">
                                    <input class="form-control" id="employName2" placeholder="输入:工号、电话、姓名" type="text"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-5">
                                </div>
                                <div class="col-sm-3">
                                    <input type="button" class="btn btn-primary" id="update" value="保存">
                                    <button type="button" class="btn btn-default" id="close_modal_update">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</@override>
<@override name="footer">
    <script type="text/javascript">
        var isMainCompany = false;
        <@shiro.isMainCompany>
        isMainCompany = true;
        </@shiro.isMainCompany>
    </script>
    <script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
    <script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="${ctx}/assets/js/zhuanxian/cars.js">
        <
        script
        src = "${ctx}/assets/js/ajaxfileupload.js" ></script>
    <script src="${ctx}/assets/js/jquery.autocomplete.min.js"></script>
    <script src="${ctx}/assets/js/jquery.paging.min.js"></script>
    <script src="${ctx}/assets/js/utils/collections.js"></script>
    <script src="${ctx}/assets/js/bootstrap-multiselect.js"></script>

<#--    <script src="${ctx}/assets/js/vue/vue.js"></script>-->
<#--    <script src="${ctx}/assets/js/iview/dist/iview.js"></script>-->
<#--    <script src="${ctx}/assets/js/iview/dist/iview.min.js"></script>-->
<#--	<script src="${ctx}/assets/js/bootstrap-select.min.js"></script>-->

    <script type="text/javascript">
        var thisButton;
        function deleteCar() {
            $.get('${ctx}/zhuanxian/deleteCar', {
                'id': thisButton.attr("data-value"),
                'lineId': thisButton.attr("data-lineId")
            }, function (data) {
                if (data.success) {
                    thisButton.parent().parent().remove();
                    $.scojs_message('车辆删除成功', $.scojs_message.TYPE_OK);
                    setTimeout(function () {
                        window.location.reload(true);
                    }, 800);
                } else {
                    $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                }
            }, 'json');
        }

        $(document).ready(function () {
            // $('#lineId').multiselect();
            $("#buyTime2").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true,
                endDate: new Date()
            });
            $("#insuranceTime2").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true,
                startDate: new Date()
            });
            $("#overhaulTime2").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true,
                startDate: new Date()
            });
            $("#buyTime").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true,
                endDate: new Date()
            });
            $("#insuranceTime").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true,
                startDate: new Date()
            });
            $("#overhaulTime").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true,
                startDate: new Date()
            });
            $(document).on("click", ".deletethis", function () {
                thisButton = $(this);
                var confirm = $.scojs_confirm({
                    content: "你真的要删除该车辆吗？",
                    action: deleteCar
                });
                confirm.show();
            });

            $('#employName').AutoComplete({
                'data': "${ctx}/zhuanxian/getDriver",
                ajaxDataType: 'json',
                ajaxParams: function (keyword) {
                    return {'param': $('#employName').val()};
                },
                'width': 'auto',
                'async': false,
                'listStyle': 'custom',
                'emphasis': false,
                'matchHandler': function (keyword, data) {
                    return true;
                },
                'createItemHandler': function (index, data) {
                    return "<span>" + data.username + "    " + data.phone + "</span>";
                },
                'afterSelectedHandler': function (data) {
                    $('#employName').val(data.username + "    " + data.phone);
                    $('#employId').val(data.id);
                }
            }).AutoComplete('show');

            //添加车辆
            $(document).on("click", ".addCar", function () {
                // $('#lineId').multiselect('destroy');
                var company_id=$("#companyId").val();
                $.get('${ctx}/zhuanxian/queryLines', {'companyId': company_id}, function (data) {
                    if (data.success) {
                        $("#lineId").html("");
                        if (data.lines != null && data.lines.length == 0) {
                            $("#lineId").append("<option value=''>" + "该公司没有线路" + "</option>")
                        } else {
                            $(data.lines).each(function (index, element) {
                                var id = data.lines[index].id;
                                var typeName = data.lines[index].name;
                                var company_name = "";
                                if (data.company_main) {
                                    company_name = "&emsp;&emsp;" + data.lines[index].companyName;
                                }
                                var text = "<option value=" + id + ">" + typeName + company_name + "</option>";
                                $("#lineId").append(text);
                            });
                            $('#lineId').multiselect({nonSelectedText:'请选择线路'});
                            $('#lineId').multiselect('refresh');
                        }
                    } else {
                        $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                    }

                }, 'json');
                $('#dialog_car').modal();
            });

<#--            <@shiro.isMainCompany>-->
<#--            window.setTimeout(function () {-->
<#--                $("#companyId").change();-->
<#--            }, 500);-->
<#--            </@shiro.isMainCompany>-->
            //公司修改后对应的车辆类型也修改
            $("#companyId").change(function () {
                var company_id = $("#companyId").val();
                $("#carTypeId").html("");
                $.get('${ctx}/zhuanxian/queryLines', {'companyId': company_id}, function (data) {
                    if (data.success) {
                        lineData = data;
                        $('#lineId').multiselect('destroy');
                        console.log("test2");
                        $("#lineId").html("");
                        if (data.lines != null && data.lines.length == 0) {
                            $("#lineId").append("<option value=''>" + "该公司没有线路" + "</option>")
                        } else {
                            $(data.lines).each(function (index, element) {
                                var id = data.lines[index].id;
                                var typeName = data.lines[index].name;
                                var company_name = "";
                                if (data.company_main) {
                                    company_name = "&emsp;&emsp;" + data.lines[index].companyName;
                                }
                                var text = "<option value=" + id + ">" + typeName + company_name + "</option>";
                                $("#lineId").append(text);

                            });
                        }

                    } else {
                        $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                    }

                }, 'json');

            });

            $("#save").click(function () {
                var companyId = $('#companyId').val();
                var companyName = $('#companyId').find("option:selected").text();
                var carName = $('#carName').val();
                var carNumber = $('#carNumber').val();

                <@shiro.isMainCompany>
                if (!companyId) {
                    $.scojs_message("请选择公司", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                </@shiro.isMainCompany>
                if (!carName.trim()) {
                    $.scojs_message("请输入车辆名称", $.scojs_message.TYPE_ERROR);
                    return false;
                }

                if (!carNumber.trim()) {
                    $.scojs_message("请输入车牌号", $.scojs_message.TYPE_ERROR);
                    return false;
                } else {
                    if (!(/^([\u4e00-\u9fa5]{1}[A-z]{1}[A-z_0-9]{5})|([\u4e00-\u9fa5]{1}[A-z]{1}[A-z_0-9]{6})|([A-z]{1,2}[0-9]{4})$/.test(carNumber))) {
                        $.scojs_message("车牌号格式不正确", $.scojs_message.TYPE_ERROR);
                        return false;
                    }
                }
                if (!$("#ridepeopleNumber").val().trim()) {
                    $.scojs_message("请输入可乘坐人数", $.scojs_message.TYPE_ERROR);
                    return false;
                } else {
                    if (parseInt($("#ridepeopleNumber").val().trim()) > 100) {
                        $.scojs_message("可乘坐人数过多", $.scojs_message.TYPE_ERROR);
                        return false;
                    }
                }
                if ($('#lineId').val() == "" || $('#lineId').val() == null) {
                    $.scojs_message("请选择路线", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                if (($('#employName').val() != null && $('#employName').val() != "") && ($('#employId').val() == null || $('#employId').val() == "")) {
                    $.scojs_message("所选服务人员不存在", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                var lines = $('#lineId').val();
                var lineId = '';
                for (var i = 0; i < lines.length; i++) {
                    lineId += lines[i];
                    if (i != lines.length - 1) {
                        lineId += ',';
                    }
                }
                $.post('${ctx}/zhuanxian/createCar',
                    {
                        'companyId': companyId,
                        'companyName': companyName,
                        'carName': carName,
                        'carNumber': carNumber,
                        'lineId': lineId,
                        'employId': $('#employId').val(),
                        'employName': $('#employName').val(),
                        'ridepeopleNumber': $("#ridepeopleNumber").val()
                    },
                    function (data) {
                        if (data.success) {
                            $.scojs_message("创建成功", $.scojs_message.TYPE_OK);
                            $('#dialog_car').modal("hide");
                            setTimeout(function () {
                                window.location.reload(true);
                            }, 800);
                        } else {
                            $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                        }
                    }, 'json');
            });
            $("#close_modal").click(function () {
                $('#dialog_car').modal("hide");
            });
            //修改车辆
            $(document).on("click", ".updatethis", function () {

                var carId = $(this).attr("data-value");
                $("#carId").val(carId);
                $.ajax({
                    type: "GET",
                    url: "${ctx}/zhuanxian/queryCar",
                    data: {id: carId},
                    dataType: "json",
                    success: function (object) {
                        var car = object.data;
                        $("#carName2").val(car.carName);
                        $("#companyId2").val(car.companyId);
                        //	$("#companyId2").change();

                        $.get('${ctx}/zhuanxian/queryLines', {'companyId': car.companyId}, function (data) {
                            if (data.success) {
                                $("#lineId2").html("");
                                if (data.lines != null && data.lines.length == 0) {
                                    $("#lineId2").append("<option value=''>" + "该公司没有线路" + "</option>")
                                } else {
                                    var set = new Set();
                                    if (car.lines != null && car.lines.length > 0) {
                                        for (var i = 0; i < car.lines.length; i++) {
                                            set.add(car.lines[i].id);
                                        }
                                    }
                                    $(data.lines).each(function (index, element) {
                                        var id = data.lines[index].id;
                                        var typeName = data.lines[index].name;
                                        var company_name = "";
                                        if (data.company_main) {
                                            company_name = "&emsp;&emsp;" + data.lines[index].companyName;
                                        }
                                        var text = '';
                                        // debugger
                                        if (set.contains(id)) {
                                            text = '<option value= ' + id + ' selected = "true">' +
                                                typeName + company_name + '</option>';
                                        } else {
                                            text = "<option value=" + id + ">" + typeName + company_name + "</option>";
                                        }
                                        $("#lineId2").append(text);

                                    });
                                    $("#carNumber2").val(car.carNumber);
                                    // $("#lineId2").val(carId);
                                    $("#employName2").val(car.employName);
                                    $("#employId2").val(car.employId);
                                    $("#ridepeopleNumber2").val(car.ridepeopleNumber);
                                    $("#status2").val(car.status);
                                    $('#lineId2').multiselect('refresh');
                                }


                            } else {
                                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                            }

                        }, 'json');


                        setTimeout(function () {

                        }, 400);

                    }
                });

                $('#dialog_car_update').modal();
            });
            //公司修改后对应的车辆类型也修改
            $("#companyId2").change(function () {
                var company_id = $("#companyId2").val();
                $("#lineId2").html("");
                $.get('${ctx}/zhuanxian/queryLines', {'companyId': company_id}, function (data) {
                    if (data.success) {
                        console.log("test1");
                        if (data.lines != null && data.lines.length == 0) {
                            $("#lineId2").append("<option value=''>" + "该公司没有线路" + "</option>")
                        } else {
                            $(data.lines).each(function (index, element) {
                                var id = data.lines[index].id;
                                var typeName = data.lines[index].name;
                                var company_name = "";
                                if (data.company_main) {
                                    company_name = "&emsp;&emsp;&emsp;&emsp;" + data.lines[index].companyName;
                                }
                                var text = "<option value=" + id + ">" + typeName + company_name + "</option>";
                                $("#lineId2").append(text);
                            });
                        }


                    } else {
                        $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                    }

                }, 'json');
            });
            $('#lineId2').change(function(){
                console.log($('#lineId2').val());
            })
            $("#update").click(function () {
                var companyId = $('#companyId2').val();
                var companyName = $('#companyId2').find("option:selected").text();
                var carName = $('#carName2').val();
                var carNumber = $('#carNumber2').val();
                <@shiro.isMainCompany>
                if (!companyId) {
                    $.scojs_message("请选择公司", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                </@shiro.isMainCompany>
                if (!carName.trim()) {
                    $.scojs_message("请输入车辆名称", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                if (!carNumber.trim()) {
                    $.scojs_message("请输入车牌号", $.scojs_message.TYPE_ERROR);
                    return false;
                } else {
                    if (!(/^([\u4e00-\u9fa5]{1}[A-z]{1}[A-z_0-9]{5})|([\u4e00-\u9fa5]{1}[A-z]{1}[A-z_0-9]{6})|([A-z]{1,2}[0-9]{4})$/.test(carNumber))) {
                        $.scojs_message("车牌号格式不正确", $.scojs_message.TYPE_ERROR);
                        return false;
                    }
                }
                if (!$("#ridepeopleNumber2").val().trim()) {
                    $.scojs_message("请输入可乘坐人数", $.scojs_message.TYPE_ERROR);
                    return false;
                } else {

                    if (parseInt($("#ridepeopleNumber2").val().trim()) > 100) {
                        $.scojs_message("可乘坐人数过多", $.scojs_message.TYPE_ERROR);
                        return false;
                    }
                }


                if ($('#lineId2').val() == "" || $('#lineId2').val() == null) {
                    $.scojs_message("请选择路线", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                if (($('#employName2').val() != null && $('#employName2').val() != "") && ($('#employId2').val() == null || $('#employId2').val() == "")) {
                    $.scojs_message("所选服务人员不存在", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                var lines = $('#lineId2').val();
                var lineId = '';
                for (var i = 0; i < lines.length; i++) {
                    lineId += lines[i];
                    if (i != lines.length - 1) {
                        lineId += ',';
                    }
                }
                console.log(lines);
                $.post('${ctx}/zhuanxian/updateCar',
                    {
                        'carId': $("#carId").val(),
                        'companyId': companyId,
                        'companyName': companyName,
                        'carName': carName,
                        'carNumber': carNumber,
                        'lineId': lineId,
                        'status': $('#status2').val(),
                        'employId': $('#employId2').val(),
                        'employName': $('#employName2').val(),
                        'ridepeopleNumber': $("#ridepeopleNumber2").val()
                    },
                    function (data) {
                        if (data.success) {
                            $('#dialog_car_update').modal("hide");
                            $.scojs_message(data.message, $.scojs_message.TYPE_OK);
                            setTimeout(function () {
                                window.location.reload(true);
                            }, 500);
                        } else {
                            $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                        }
                    }, 'json');
            });

            $("#close_modal_update").click(function () {
                $('#dialog_car_update').modal("hide");
            });

            $('#employName2').AutoComplete({
                'data': "${ctx}/zhuanxian/getDriver",
                ajaxDataType: 'json',
                ajaxParams: function (keyword) {
                    $('#employId2').val("");
                    return {'param': $('#employName2').val()};
                },
                'width': 'auto',
                'async': false,
                'listStyle': 'custom',
                'emphasis': false,
                'matchHandler': function (keyword, data) {
                    return true;
                },
                'createItemHandler': function (index, data) {
                    return "<span>" + data.username + "    " + data.phone + "</span>";
                },
                'afterSelectedHandler': function (data) {
                    $('#employName2').val(data.username + "    " + data.phone);
                    $('#employId2').val(data.id);
                }
            }).AutoComplete('show');
        });

    </script>
</@override>
<@extends name="../layout.ftl"/>
